package com.geek.javase.ArrayListWork;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author chenshupeng
 * @date 2025/9/4
 * @desc TODO
 **/

public class Test {
    public static void main(String[] args) {
        ArrayList<User> users = new ArrayList<User>();
        users.add(new User("小王", "1"));
        users.add(new User("小赵", "2"));
        users.add(new User("小钱", "3"));
        users.add(new User("小孙", "4"));
        users.add(new User("小李", "5"));


        Scanner sc = new Scanner(System.in);
        int chance=3;
        while(chance>0)
        {
            System.out.println("请输入用户名");
            String name=sc.nextLine();
            System.out.println("请输入密码");
            String password=sc.nextLine();
            boolean flag=false;
            for(User user:users)
            {
                if(user.getName().equals(name)&&user.getPassword().equals(password))
                    flag=true;
                break;
            }

            if(flag)
            {
                System.out.println("登录成功");
                break;
            }
            else{
                chance--;
                System.out.println("密码或者用户名错误，剩余"+chance+"次数");
            }

        }
    }
}
